// Chengji.java
import java.util.HashMap;
import java.util.Map;

public class Chengji {
    private Xuehao xuehao;
    private Map<Kecheng, Double> kechengChengjiMap; // 课程到成绩的映射

    public Chengji(Xuehao xuehao) {
        this.xuehao = xuehao;
        this.kechengChengjiMap = new HashMap<>();
    }

    public Xuehao getXuehao() {
        return xuehao;
    }

    public void setXuehao(Xuehao xuehao) {
        this.xuehao = xuehao;
    }

    public void addChengji(Kecheng kecheng, double chengji) {
        kechengChengjiMap.put(kecheng, chengji);
    }

    public double getChengji(Kecheng kecheng) {
        return kechengChengjiMap.getOrDefault((Object) kecheng, (double) -1); // 如果课程不存在返回-1
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(xuehao.toString()).append("\n");
        for (Map.Entry<Kecheng, Double> entry : kechengChengjiMap.entrySet()) {
            sb.append(entry.getKey()).append(", 成绩: ").append(entry.getValue()).append("\n");
        }
        return sb.toString();
    }
}
